{% extends "base/base.html" %}

{% block content %}
    <div class="col-md-12 col-sm-12 col-xs-12" xmlns="http://www.w3.org/1999/html">
        <div class="x_panel">
            <div class="x_title">
                <h2><i class="fa fa-bars"></i> 执行任务
                </h2>
                <ul class="nav navbar-right panel_toolbox">
                    <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                           aria-expanded="false"><i class="fa fa-wrench"></i></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="#">Settings 1</a>
                            </li>
                            <li><a href="#">Settings 2</a>
                            </li>
                        </ul>
                    </li>
                    <li><a class="close-link"><i class="fa fa-close"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <form id="taskConfForm" method="POST">
                    {% csrf_token %}
                    <div class="form-group">
                        <label for="message">执行帐号</label>
                        <input type="text" class="form-control" name="run_user" placeholder="root"
                               value="{{ conf.default_user }}">
                    </div>
                    <div class="form-group">
                        <label for="message">任务描述</label>
                        <input type="text" class="form-control" name="desc" placeholder="来一个简单的描述" value="">
                    </div>
                    <div class="form-group">
                        <label for="message">执行超时时间(s)</label>
                        <input type="text" class="form-control" name="timeout" placeholder="超时时间"
                               value="{{ conf.timeout }}">
                    </div>
                    <div class="form-group">
                        <label for="message">目标主机</label>
                        <input id="host_list" name="hosts" type="text" class="form-control" value=""
                               placeholder="主机列表"/>
                    </div>

                    {% if params %}
                        {% for param in params %}
                            <div class="form-group" id="vars">
                                <label for="message">{{ param.name }}</label>
                                {% ifequal param.type 'input' %}
                                    <input class="date-picker form-control col-md-7 col-xs-12 name"
                                           {% if param.required %}required="required" {% endif %}
                                           name="{{ param.name }}" type="input" placeholder="{{ param.desc }}"
                                           value="{{ param.default }}">
                                {% endifequal %}
                                {% ifequal param.type 'text' %}
                                    <textarea class="date-picker form-control col-md-7 col-xs-12 desc"
                                              {% if param.required %}required="required" {% endif %}
                                              name="{{ param.name }}"
                                              placeholder="{{ param.desc }}">{{ param.default }}</textarea>
                                {% endifequal %}
                                {% ifequal param.type 'int' %}
                                    <input class="date-picker form-control col-md-7 col-xs-12 name"
                                           {% if param.required %}required="required" {% endif %}
                                           name="{{ param.name }}" type="number" placeholder="{{ param.desc }}"
                                           value="{{ param.default }}">
                                {% endifequal %}
                            </div>
                        {% endfor %}
                    {% endif %}

                    <input type="submit" class="btn btn-primary" value="执行任务"/>
                </form>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script>
        $(document).ready(function () {
            $('#host_list').tagsInput({
                width: 'auto',
                defaultText: '主机列表'
            });
        });
    </script>
{% endblock %}